﻿using MediatR;
using SU.Center.Domain.SY;
using SU.Center.Infa;

namespace SU.Center.Api.Handler.TraceabilityMethod
{
    /// <summary>
    /// 删除信息
    /// </summary>
    public class DelInformationHandler : IRequestHandler<DelInformationRequestDto, ApiResult>
    {
        private readonly ILogger<DelInformationHandler> logger;
        private readonly IBaseReposiotry<Information> baseReposiotry;

        public DelInformationHandler(ILogger<DelInformationHandler> logger, IBaseReposiotry<Information> baseReposiotry)
        {
            this.logger = logger;
            this.baseReposiotry = baseReposiotry;
        }

        public async Task<ApiResult> Handle(DelInformationRequestDto request, CancellationToken cancellationToken)
        {
            var list = await baseReposiotry.GetAsync(x => x.InformationId == request.InformationId);
            list.InformationDel = true;
            await baseReposiotry.UpdateAsync(list);
            return ApiResult.Ok("删除成功");
        }
    }
}

public class DelInformationRequestDto : IRequest<ApiResult>
{
    public int InformationId { get; set; }
}
